package demo.repository;

import demo.entity.Salary;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 薪资 Dao
 *
 * @author 肖溥博文
 * @version 1.0
 */
@Repository
public interface SalaryRepository extends JpaRepository<Salary, Long> {

    /**
     * 获取在职信息对应的最新的薪资 id
     *
     * @param userCompanyId 在职信息 id
     * @return 薪资 id
     */
    @Query("select max(id) from Salary where userCompanyId = :userCompanyId")
    Long findLatestSalaryIdByUserCompanyId(@Param("userCompanyId") Long userCompanyId);

    /**
     * 获取薪资 id 对应的薪资
     *
     * @param id 薪资 id
     * @return 薪资对象
     */
    Salary findSalaryById(Long id);

    /**
     * 获取在职信息对应的所有薪资
     *
     * @param userCompanyId 在职信息 id
     * @return 薪资对象数组
     */
    List<Salary> findAllByUserCompanyId(Long userCompanyId);
}
